package mysocket




import java.io.{ObjectInputStream, ObjectOutput, ObjectOutputStream}
import java.net.{ServerSocket, Socket}



// 服务端
object Server {
  def main(args: Array[String]): Unit = {
    val serverSocket: ServerSocket = new ServerSocket(8888)
    val clientSocket: Socket = serverSocket.accept()

    val inputStream = new ObjectInputStream(clientSocket.getInputStream)

    val outputStream = new ObjectOutputStream(clientSocket.getOutputStream)

//    val socketServer: ServerSocket = new ServerSocket(8888)
//    var clientSocket: Socket = socketServer.accept()
//    println("*******************************************")
//    //val inputStream = new ObjectInputStream(clientSocket.getInputStream)
//    //val outputStream = new ObjectOutputStream(clientSocket.getOutputStream)
//    val inputStream = new ObjectInputStream(clientSocket.getInputStream)
//    println("111*******************************************")
//    val outputStream = new ObjectOutputStream(clientSocket.getOutputStream)

    println("111*******************************************")
    val value = inputStream.readObject()

    println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    value match {
      case RegisterMsg(username, password ) => {
        println(s"username:${username}, password:${password}")
        println("注册完成")
      }
      case HeartBeat(host , currenttime) =>{
        println(s"host: ${host}, currenttime:${currenttime}")
        println("收到心跳了")
      }
      case _ => println("接受。。。。。")
    }
  }
}
